package com.shu.framework.utils;


import org.apache.commons.codec.digest.DigestUtils;

/**
 * md5加密
 */
public class MD5Util {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }
    private static final String salt="1a2b3c4d";

    /**
     * 明文密码转表单密码
     * @param inputPass
     * @return
     */
    public static String inputPassToFormPass(String inputPass){
        String str=""+salt.charAt(0)+salt.charAt(2)+inputPass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }

    /**
     * 表单密码转数据库密码
     * @param formPass
     * @param salt
     * @return
     */
    public static String formPassToDBPass(String formPass,String salt){
        String str=""+salt.charAt(0)+salt.charAt(2)+formPass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }

    /**
     * 调用上面两个方法
     * @param input
     * @param saltDB
     * @return
     */
    public static String inputPassToDbPass(String input,String saltDB){
        return formPassToDBPass(inputPassToFormPass(input),saltDB);
    }
    public static void main(String[] args) {
        System.out.println(inputPassToDbPass("123456","1a2b3c4d"));
        System.out.println(inputPassToFormPass("123456"));//d3b1294a61a07da9b49b6e22b2cbd7f9
    }
}
